package kr.saeildamil.androidstudy.ch11;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

public class TextChange extends Activity {
	EditText et;
	TextView tv;
//교재 529페이지 textchange 536페이지  inoutfilter
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_textchange);
		et = (EditText) findViewById(R.id.ch11_textchagne_edit);
		tv = (TextView) findViewById(R.id.ch11_textchagne_textView);
		
		et.setFilters(new InputFilter[] {
			new InputFilter.LengthFilter(10)
		});
		et.addTextChangedListener(watcher);
	}

	TextWatcher watcher = new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			int etSize = et.getText().toString().length();
			tv.setText("글자수: " + etSize + "bytes");
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}

		public void afterTextChanged(Editable s) {
		}

	};
}
